package com.ncloud.resman.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.ncloud.resman.entity.ExportIpAddress;
import com.ncloud.resman.entity.ImportIpAddress;
import com.ncloud.resman.entity.IpAddress;

/**
 * user:sundelong  date:2017年8月30日
 */
@Mapper
public interface NetworkExcelMapper {
	@Select(" SELECT net_type,f_get_dict('net_type',net_type) as net_type_name,ip_segment, ip,"
			+ "f_get_dict('ip_state',state) as state, apply_person, purpose, remarks FROM res_ip_address where "
			+ "(#{0}=0 or net_type = #{0}) and (#{1}=0 or ip_segment = #{1}) and (#{2}=2 or state = #{2}) and"
			+ " (#{3}='' or ip = #{3})")
	@Results({
		@Result(column="id",property="id"),@Result(column="net_type",property="netType"),
		@Result(column="net_type_name",property="netTypeName"),@Result(column="ip_segment",property="ipSegment"),
		@Result(column="ip",property="ip"),@Result(column="state",property="state"),
		@Result(column="apply_person",property="applyPerson"),@Result(column="purpose",property="purpose"),
		@Result(column="create_user",property="createUser"),@Result(column="create_date",property="createDate"),
		@Result(column="update_user",property="updateUser"),@Result(column="update_date",property="updateDate"),
		@Result(column="remarks",property="remarks")})
	List<ExportIpAddress> getIpAddressList(String netType,String ipSegment,String state,String ip);
	
	@Insert("INSERT INTO res_ip_address (id, net_type, ip_segment, ip, state, create_user, create_date, remarks) "
			+ " values(#{id},#{netType},#{ipSegment},#{ip},#{state},#{createUser},now(),#{remarks})")
	int exportIpAddress(ImportIpAddress importIpAddress);
}
